<%
'*****************************************************
'Description:系统所有功能函数
'Copyright:Copyright(c)2012
'Company:204studio
'@author:klarkyang
'@version:1.0
'******************************************************
%>
<%
'==================================================================================
'函数功能:注销用户
'函数返回值:无
'参数说明:无
'Author:klarkyang
'==================================================================================
sub loginout()
	session("usertype")=""
	session("username")=""
	session("realname")=""
	session.Abandon()
	Response.Redirect("index.asp")
end sub
'==================================================================================
'函数功能:根据username更新管理员密码
'函数返回值:无
'参数说明:无
'Author:klarkyang
'==================================================================================
sub adminUpdatePassword(username)
	sql="select * from cw_users where username='"&username&"'"
    set rs = ado_iquery(sql,conn,3,3)
	password = request.Form("password")
	if password <> "" then
		rs("password")= sha1(password)
	end if
	rs("edittime")=now()
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能:根据roleCollection解析角色列表,显示相应角色
'函数返回值:showRoleListByRoleCollection 角色名称
'参数说明:roleCollection(角色字符串)
'Author:klarkyang
'==================================================================================
Function showRoleListByRoleCollection(roleCollection)
	if roleCollection<>"" then
		roleArray = Split(roleCollection,",")
		for j=LBound(roleArray) to UBound(roleArray)
			sql = "select * from cw_roles where roleId="&trim(roleArray(j))
			set rs_role = ado_query(sql) 
			if not rs_role.eof then
				showRoleListByRoleCollection = showRoleListByRoleCollection&"<div class='operList'>["&rs_role("roleName")&"]</div>"
			end if
			rs_role.close : set rs_role=nothing
		next
	end if
End Function
'==================================================================================
'函数功能:根据用户名列出所有角色
'函数返回值:无
'参数说明:username,field_id
'Author:klarkyang
'==================================================================================
function showRoleByUsername(username,field_id)
	sql = "select * from cw_users where username='"&username&"'"
	set rs_user = ado_query(sql)
	if rs_user("roleCollection")<>"" then
		roleArray = Split(rs_user("roleCollection"),",")
		'循环每个角色
		for j=LBound(roleArray) to UBound(roleArray)
			sql = "select * from cw_roles where roleId="&trim(roleArray(j))
			set rs_role = ado_query(sql)
			'解析操作列表
			if rs_role("operCollection")<>"" then
				operArray = Split(rs_role("operCollection"),",")
				for m=LBound(operArray) to UBound(operArray)
					sql = "select * from cw_operations where operId="&trim(operArray(m))
					set rs_oper = ado_query(sql)
					if CInt(field_id)=CInt(trim(operArray(m))) then
						showRoleByUsername = showRoleByUsername&"<div class='operList'>[<a href='"&rs_oper("operUrl")&"'>"&rs_oper("operName")&"</a>]</div>"
						Exit Function
					end if
					rs_oper.close : set rs_oper=nothing
				next
			end if
		next
	end if
	rs_user.close : set rs_user=nothing
end function
'==================================================================================
'函数功能: 添加模块
'函数返回值:无
'参数说明:
'Author:klarkyang
'==================================================================================
sub insertOperations()
	sql="select * from cw_operations"
    set rs = ado_iquery(sql,conn,1,3)
    rs.addnew
	rs("operName")=request.Form("operName")
	rs("operUrl")=request.Form("operUrl")
	rs("remark")=request.Form("remark")
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 更新模块
'函数返回值:无
'参数说明:id
'Author:klarkyang
'==================================================================================
sub updateOperations(id)
	sql="select * from cw_operations where id="&id
	set rs = ado_iquery(sql,conn,3,3)
	rs("operName")=request.Form("operName")
	rs("operUrl")=request.Form("operUrl")
	rs("remark")=request.Form("remark")
	rs("edittime")=now()
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能:删除记录
'函数返回值:
'参数说明:
'Author:klarkyang
'==================================================================================
sub delQuery(tableName,idName,id)
	sql="delete from "&tableName&" where "&idName&" in ("&id&")"
	if id<>"" then
		conn.execute(sql)
	end if
end sub
'==================================================================================
'函数功能: 添加角色
'函数返回值:无
'参数说明:
'Author:klarkyang
'==================================================================================
sub insertRoles()
	sql="select * from cw_roles"
	set rs = ado_iquery(sql,conn,1,3)
    rs.addnew
	rs("roleName")=request.Form("roleName")
	rs("operCollection")=request.Form("operList")
	rs("remark")=request.Form("remark")
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 更新角色
'函数返回值:无
'参数说明:
'Author:klarkyang
'==================================================================================
sub updateRoles(id)
	sql="select * from cw_roles where id="&id
	set rs=ado_iquery(sql,conn,3,3)
	rs("roleName")=request.Form("roleName")
	rs("operCollection")=request.Form("operList")
	rs("remark")=request.Form("remark")
	rs("edittime")=now()
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 更新用户
'函数返回值:无
'参数说明:id
'Author:klarkyang
'==================================================================================
sub updateUsers(id)
	sql="select * from cw_users where id="&id
    set rs = ado_iquery(sql,conn,3,3)
	password = request.Form("password")
	if password <> "" then
		rs("password")= sha1(password)
	end if
	rs("realName")=request.Form("realName")
	rs("telNum")=request.Form("telNum")
	rs("roleCollection")=request.Form("roleList")
	rs("edittime")=now()
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 添加管理用户信息
'函数返回值:无
'参数说明:id
'Author:klarkyang
'==================================================================================
sub insertUsers()
	sql="select * from cw_users"
	set rs = ado_iquery(sql,conn,1,3)
	rs.addnew
	rs("username")=request.Form("username")
	password = request.Form("password") : rs("password")=sha1(password)
	rs("realName")=request.Form("realName")
	rs("telNum")=request.Form("telNum")
	rs("roleCollection")=request.Form("roleList")
	rs.update
	rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 更新管理用户信息（包含用户级别、职务管理）
'函数返回值:无
'参数说明:id
'Author:klarkyang
'==================================================================================
sub updateCommonUsers(id)
	'操作cw_users表
	sql="select * from cw_users where id="&id
    set rs = ado_iquery(sql,conn,3,3)
	password = request.Form("password")
	if password <> "" then
		rs("password")= sha1(password)
	end if
	rs("realName")=request.Form("realName")
	rs("telNum")=request.Form("telNum")
	level=request.Form("level")
	rs("roleCollection") = trim(request.Form("selectRole"))
	rs("edittime")=now()
	rs.update
    rs.close : set rs=nothing
	
	'操作cw_usersLevel表
	sql ="select * from cw_usersLevel where id="&id
	set rs=ado_iquery(sql,conn,3,3)
	rs("level")= level
	if level = "1" then
		rs("collegeid")=""
		rs("classCollection")=""
	elseif level="2" then
		rs("collegeid")=request.Form("collegeid")
		rs("classCollection")=""
	elseif level="3" then
		rs("collegeid")=request.Form("collegeid")
		rs("classCollection")=request.Form("classCollection")
	end if
	rs.update
    rs.close : set rs=nothing
end sub
'==================================================================================
'函数功能: 添加管理用户信息(包含用户级别与职务)
'函数返回值:无
'参数说明:
'Author:klarkyang
'==================================================================================
sub insertCommonUsers()
	'操作cw_users表
		sql="select * from cw_users"
    	set rs = ado_iquery(sql,conn,1,3)
    	rs.addnew
		rs("username")=request.Form("username")
		password = request.Form("password") : rs("password")=sha1(password)
		rs("realName")=request.Form("realName")
		rs("telNum")=request.Form("telNum")
		level=request.Form("level")
		rs("roleCollection") = trim(request.Form("selectRole"))
		rs.update
		rs.movelast
		id = rs("id")
		rs.close : set rs=nothing
		
		'操作cw_usersLevel表
		sql = "select * from cw_usersLevel"
		set rs = ado_iquery(sql,conn,1,3)
    	rs.addnew
		rs("id")=id
		rs("level")= level
		if level = "1" then
			rs("collegeid")=""
			rs("classCollection")=""
		elseif level="2" then
			rs("collegeid")=request.Form("collegeid")
			rs("classCollection")=""
		elseif level="3" then
			rs("collegeid")=request.Form("collegeid")
			rs("classCollection")=request.Form("classCollection")
		end if
		rs.update
		rs.close : set rs=nothing
end sub

'==================================================================================
'函数功能:根据collegeid、majorid显示专业列表<option>
'函数返回值:
'参数说明:collegeid,majorid
'Author:klarkyang
'==================================================================================
sub showMajorOptionListByCollegeidAndMajorid(byval collegeid,majorid)
	if collegeid="" or collegeid=-1 or isNull(collegeid) then
		sql="select * from stu_majorlist"
	else
		sql="select * from stu_majorlist where collegeid="&collegeid
	end if
	'-2代表空值
	if majorid="" or isNull(majorid) then
		majorid=-2
	end if
	set rs_majorlist=conn.execute(sql)
	echo "<option value=''>--未选择--</option>"
	if not (rs_majorlist.bof or rs_majorlist.eof) then
		do while not rs_majorlist.eof
			if Cstr(majorid) = Cstr(rs_majorlist("majorid")) then
				response.Write("<option value='"&rs_majorlist("majorid")&"' selected='selected'>"&rs_majorlist("majorname")&"</option>")
			else 
				response.Write("<option value='"&rs_majorlist("majorid")&"'>"&rs_majorlist("majorname")&"</option>")
			end if
		rs_majorlist.movenext
		loop
	end if
	rs_majorlist.close : set rs_majorlist=nothing
end sub

'==================================================================================
'函数功能:根据collegeid、classid显示专业列表<option>
'函数返回值:
'参数说明:collegeid,classid
'Author:klarkyang
'==================================================================================
sub showClassOptionListByCollegeidAndClassid(byval collegeid,byval classid)
	if collegeid="" or collegeid=-1 or isNull(collegeid)  then
		sql="select * from stu_classlist"
	else
		sql="select * from stu_classlist where collegeid="&collegeid
	end if
	set rs_classlist=conn.execute(sql)
	'-2代表空值
	if classid="" or isNull(classid) then
		classid=-2
	end if
	echo "<option value=''>--未选择--</option>"
	if not (rs_classlist.bof or rs_classlist.eof) then
		do while not rs_classlist.eof
			if Cstr(classid) = Cstr(rs_classlist("classid")) then
				response.Write("<option value='"&rs_classlist("classid")&"' selected='selected'>"&rs_classlist("classname")&"</option>")
			else 
				response.Write("<option value='"&rs_classlist("classid")&"'>"&rs_classlist("classname")&"</option>")
			end if
		rs_classlist.movenext
		loop
	end if
	rs_classlist.close : set rs_classlist=nothing
end sub

'==================================================================================
'函数功能:根据collegeid、departmentid显示系所列表<option>
'函数返回值:
'参数说明:collegeid,departmentid
'Author:klarkyang
'==================================================================================
sub showDepartmentOptionListByCollegeidAndDepartmentid(byval collegeid,byval departmentid)
	if collegeid="" or collegeid=-1 or isNull(collegeid) then
		sql="select * from stu_departmentlist"
	else
		sql="select * from stu_departmentlist where departmentid in (select departmentid from stu_departmentlist where collegeid="&collegeid&")"
	end if
	'-2代表空值
	if departmentid="" or isNull(departmentid) then
		departmentid=-2
	end if
	set rs_departmentlist=conn.execute(sql)
	echo "<option value=''>--未选择--</option>"
	echo "<option value='-1'>--未建系--</option>"
	if not (rs_departmentlist.bof or rs_departmentlist.eof) then
		do while not rs_departmentlist.eof
			if departmentid=rs_departmentlist("departmentid") then
				response.Write("<option value='"&rs_departmentlist("departmentid")&"' selected='selected'>"&rs_departmentlist("deparname")&"</option>")
			else
				response.Write("<option value='"&rs_departmentlist("departmentid")&"'>"&rs_departmentlist("deparname")&"</option>")
			end if
		rs_departmentlist.movenext
		loop
	end if
	rs_departmentlist.close : set rs_departmentlist=nothing
end sub

'==================================================================================
'函数功能:读取简单<option>列表
'函数返回值:无
'参数说明:queryId传入ID值,tableName待操作的表名,idColumn （ID列的名称）,nameColumn （name列的名称）
'Author:klarkyang
'==================================================================================
sub showOptionList(queryId,tableName,idColumn,nameColumn)
	if queryId="" then
		'-2代表空值
		queryId = -2
	end if
	sql="select * from "&tableName
	set rs_optionlist=conn.execute(sql)
	echo "<option value=''>--未选择--</option>"
	do while not rs_optionlist.eof
		if CInt(queryId)=CInt(rs_optionlist(idColumn)) then
			response.Write("<option value='"&rs_optionlist(idColumn)&"' selected='selected'>"&rs_optionlist(nameColumn)&"</option>")
		else
			response.Write("<option value='"&rs_optionlist(idColumn)&"'>"&rs_optionlist(nameColumn)&"</option>")
		end if
	rs_optionlist.movenext
	loop
	rs_optionlist.close : set rs_optionlist=nothing
end sub

'==================================================================================
'函数功能:单选框表单，用于2项，更新
'函数返回值:无
'参数说明:columnValue数据列值，value1第一个选项值，value2第二个选项值，columnName数据列名称，value1Name第一个选项名称，value2Name第二个选项名称,validatIsnot是否为必填项，isNoSelect是否包含未选择项
'Author:klarkyang
'==================================================================================
sub twoRadioUpdate(columnValue,value1,value2,columnName,value1Name,value2Name,validatIsnot,isNoSelect)
	if Cstr(columnValue)=Cstr(value1) then
		response.Write "<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value1&"' checked='checked'/>"&value1Name&"<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value2&"' />"&value2Name
	elseif Cstr(columnValue)=Cstr(value2) then
		response.Write "<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value1&"' />"&value1Name&"<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value2&"' checked='checked'/>"&value2Name
	else
		if validatIsnot=0 then
			response.Write "<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value1&"'/>"&value1Name&"<input type='radio' name='"&columnName&"' id='"&columnName&"' value='2'/>"&value2Name
		elseif validatIsnot=1 then
			response.Write "<input type='radio' name='"&columnName&"' id='"&columnName&"' value='"&value1&"'/>"&value1Name&"<input type='radio' name='"&columnName&"' id='"&columnName&"' value='2' dataType='Group'  msg='此项不能为空'/>"&value2Name
		end if
	end if
	if isNoSelect=1 then
		response.Write "<input type='radio' name='"&columnName&"' id='"&columnName&"' value=''/>全部"
	end if
end sub

'==================================================================================
'函数功能:简单2项根据数值输出名称
'函数返回值:
'参数说明:valueContent传入数值,value1第一项值,value2第二项值,valueName1第一项名称,valueName2第二项名称
'Author:klarkyang
'==================================================================================
sub twoNameByValue(valueContent,value1,value2,valueName1,valueName2)
	if valueContent=value1 then
		response.Write(valueName1)
	elseif valueContent=value2 then
		response.Write(valueName2)
	else
		response.Write("未知")
	end if
end sub



'函数：显示所有角色复选框列表
Function showRoleCheckboxList()
	sql = "select * from cw_roles order by editTime desc"
	set rs_role = ado_query(sql)
	do while not rs_role.eof
		showRoleCheckboxList = showRoleCheckboxList&"<div class='operList'><input name='roleList' type='checkbox' value='"&rs_role("id")&"' class='input_noborder' dataType='Group' msg='至少选择一个'/>"&rs_role("roleName")&"</div>"
		rs_role.movenext
	loop
	rs_role.close : set rs_role=nothing
End Function

'函数：显示编辑状态下角色复选框列表
Function showEditRoleCheckboxList(roleCollection)
	sql = "select * from cw_roles order by editTime desc"
	set rs_role = ado_query(sql)
	do while not rs_role.eof
		if roleCollection<>"" then
			roleArray = Split(roleCollection,",")
			for i=LBound(roleArray) to UBound(roleArray)
				if rs_role("id")=CInt(trim(roleArray(i))) then
					showEditRoleCheckboxList = showEditRoleCheckboxList&"<div class='operList'><input name='roleList' type='checkbox' value='"&rs_role("id")&"' class='input_noborder' checked='checked' dataType='Group' msg='至少选择一个'/>"&rs_role("roleName")&"</div>"
					exit for
				end if
			next
			if i>UBound(roleArray) then
				showEditRoleCheckboxList = showEditRoleCheckboxList&"<div class='operList'><input name='roleList' type='checkbox' value='"&rs_role("id")&"' class='input_noborder' dataType='Group' msg='至少选择一个'/>"&rs_role("roleName")&"</div>"
			end if
		end if
	rs_role.movenext
	loop
	rs_role.close : set rs_role=nothing
End Function


'函数：根据operCollection解析操作列表
Function showOperListByOperCollection(operCollection)
	if operCollection<>"" then
		operArray = Split(operCollection,",")
		for j=LBound(operArray) to UBound(operArray)
 			sql_oper = "select * from cw_operations where operId="&trim(operArray(j))
			set rs_oper = ado_query(sql_oper)
			if not rs_oper.eof then
				showOperListByOperCollection = showOperListByOperCollection&"<div class='operList'>["&rs_oper("operName")&"]</div>"
			end if
			rs_oper.close : set rs_oper=nothing
		next
	end if
End Function

'函数：显示操作复选框列表
function showOperCheckboxList()
	sql = "select * from cw_operations order by editTime desc"
	set rs_oper = ado_query(sql)
	do while not rs_oper.eof
		showOperCheckboxList = showOperCheckboxList&"<div class='operList'><input name='operList' type='checkbox' value='"&rs_oper("operId")&"' class='input_noborder' dataType='Group' msg='至少选择一个'/>"&rs_oper("operName")&"</div>"
	rs_oper.movenext
	loop
	rs_oper.close : set rs_oper=nothing
	conn.close : set conn=nothing
end function

'函数：显示编辑状态下操作复选框列表
Function showEditOperCheckboxListByOperCollection(operCollection)
	sql_oper = "select * from cw_operations order by editTime desc"
	set rs_oper = ado_query(sql_oper)
	do while not rs_oper.eof
		if operCollection<>"" then
			operArray = Split(operCollection,",")
			for i=LBound(operArray) to UBound(operArray)
				if rs_oper("id")=CInt(trim(operArray(i))) then
					showEditOperCheckboxListByOperCollection = showEditOperCheckboxListByOperCollection&"<div class='operList'><input name='operList' type='checkbox' value='"&rs_oper("id")&"' class='input_noborder' checked='checked' dataType='Group' msg='至少选择一个'/>"&rs_oper("operName")&"</div>"
					exit for
				end if
			next
			if i>UBound(operArray) then
				showEditOperCheckboxListByOperCollection = showEditOperCheckboxListByOperCollection&"<div class='operList'><input name='operList' type='checkbox' value='"&rs_oper("id")&"' class='input_noborder' dataType='Group' msg='至少选择一个'/>"&rs_oper("operName")&"</div>"
			end if
		end if
	rs_oper.movenext
	loop
	rs_oper.close : set rs_oper=nothing
End Function
'==================================================================================
'函数功能: 显示用户级别
'函数返回值:无
'参数说明:level
'Author:klarkyang
'==================================================================================
function showLevel(byval level)
	select case level
		case 1 echo "校级"
		case 2 echo "院级"
		case 3 echo "班级"
	end select
end function

'显示学院名称
function showCollegename(collegeid)
	if collegeid<>"" then
		sql = "select collegename from cw_colleges where collegeid="&collegeid
		set rs_collegename = ado_query(sql)
		if not rs_collegename.eof then
			showCollegename = rs_collegename("collegename")
		else
			showCollegename = ""
		end if
		rs_collegename.close : set rs_collegename = nothing
	end if
end function

'解析并显示班级列表
function showClassListByClassCollection(classCollection)
	if classCollection<>"" then
		classArray = Split(classCollection,",")
		for j=LBound(classArray) to UBound(classArray)
 			if trim(classArray(j))<>"" then
				sql = "select * from stu_classlist where classid="&trim(classArray(j))
				'echo "-"&trim(classArray(j))
				set rs_classCollection = ado_query(sql)
				if not rs_classCollection.eof then
					showClassListByClassCollection = showClassListByClassCollection&"<div class='operList'>["&rs_classCollection("className")&"]</div>"
				else 
					showClassListByClassCollection = showClassListByClassCollection&"<div class='operList'>[未知班级]</div>"
				end if
				rs_classCollection.close : set rs_classCollection=nothing
			end if
		next
	end if
end function

'==================================================================================
'函数功能:根据collegeid显示学院列表<option>
'函数返回值:
'参数说明:collegeidLevel(用户表中的collegeid),collegeid(当前表中的collegeid)
'Author:klarkyang
'==================================================================================
sub showCollegeOptionListByCollegeid(collegeidLevel,byval collegeid)
	if collegeidLevel="" or collegeidLevel=-1 or isNull(collegeidLevel) then
		sql="select * from cw_colleges"
		echo "<option value=''>--未选择--</option>"
	else
		sql="select * from cw_colleges where collegeid="&collegeidLevel
	end if
	'-2代表空值
	if collegeid="" or isNull(collegeid) then
		collegeid=-2
	end if
	set rs_collegelist=conn.execute(sql)
	if not (rs_collegelist.bof or rs_collegelist.eof) then
		do while not rs_collegelist.eof
			if Cstr(collegeid) = Cstr(rs_collegelist("collegeid")) then
				response.Write("<option value='"&rs_collegelist("collegeid")&"' selected='selected'>"&rs_collegelist("collegename")&"</option>")
			else
				response.Write("<option value='"&rs_collegelist("collegeid")&"'>"&rs_collegelist("collegename")&"</option>")
			end if
		rs_collegelist.movenext
	loop
	end if
	rs_collegelist.close : set rs_collegelist=nothing
end sub

'==================================================================================
'函数功能: 判断用户管理范围（超级、校、院、班）
'函数返回值:userLevel数组含3个值：级别ID、学院ID、班级集合(以逗号分隔)
'参数说明:
'Author:klarkyang
'==================================================================================
function userLevel()
	username = session("username")
	sql = "select * from cw_users where username = '"&username&"'"
	set rs_level = ado_query(sql)
	if not rs_level.eof then
		level = rs_level("userLevel")
		collegeid = rs_level("collegeid")
		classCollection = rs_level("classCollection")
		userLevel = array(level,collegeid,classCollection) 
	else
		userLevel = array("0","","")
	end if
	rs_level.close : set rs_level = nothing
end function

'根据collegeid显示所有相应班级option列表
function showClassOptionListByCollegeid(collegeid)
	sql = "select * from stu_classlist where collegeid = "&collegeid&" order by classname asc"
	set rs_classlist = ado_query(sql)
	do while not rs_classlist.eof
		classidQuery = classidQuery&rs_classlist("classid")&","
		classnameQuery = classnameQuery&rs_classlist("classname")&","
		showClassOptionListByCollegeid = array(classidQuery,classnameQuery)
	rs_classlist.movenext
	loop
	rs_classlist.close : set rs_classlist = nothing
end function

'==================================================================================
'函数功能: 显示用所管理的班级option
'函数返回值:showClassOptionListEdit学院<option>字串
'参数说明:collegeid学院ID,classCollection班级集合字串
'Author:klarkyang
'==================================================================================
function showClassOptionListEdit(collegeid,classCollection)
	if classCollection="" or IsNull(classCollection)=true then
		classCollection = -1 '如果classCollection为空赋初始值
	end if
	if collegeid="" or IsNull(collegeid)=true then
		collegeid = -1 '如collegeid为空赋初始值
	end if
	classArray = Split(classCollection,",")
	sql = "select * from stu_classlist where collegeid = "&collegeid&" order by classname asc"
	set rs_classlist = ado_query(sql)
	do while not rs_classlist.eof	
		flag=0  '判断是否被选中0表示否1表示是
		for j=LBound(classArray) to UBound(classArray)
			if CStr(trim(classArray(j))) = CStr(rs_classlist("classid")) then
				flag=1
			end if
		next
		if flag = 1 then
			showClassOptionListEdit = showClassOptionListEdit&"<option value='"&rs_classlist("classid")&"' selected='selected'>"&rs_classlist("classname")&"</option>"
		else
			showClassOptionListEdit = showClassOptionListEdit&"<option value='"&rs_classlist("classid")&"'>"&rs_classlist("classname")&"</option>"
		end if
	rs_classlist.movenext
	loop
	rs_classlist.close : set rs_classlist = nothing
	'showClassOptionListEdit = classCollection
end function

'==================================================================================
'函数功能: 根据collegeid显示collegename
'函数返回值:showOneCollegeOption选中学院的<option>
'参数说明:collegeid 学院ID
'Author:klarkyang
'==================================================================================
function showOneCollegeOption(collegeid)
	if collegeid<>"" then
		sql = "select * from cw_colleges where collegeid ="&collegeid
		set rs_collegeOption=ado_query(sql)
		showOneCollegeOption = "<option value='"&rs_collegeOption("collegeid")&"' selected='selected'>"&rs_collegeOption("collegename")&"</option>"
	end if
end function


'==================================================================================
'函数功能:解析并显示班级列表
'函数返回值:showOneCollegeOption选中学院的<option>
'参数说明:collegeid 学院ID
'Author:klarkyang
'==================================================================================
function showClassNameByClassCollection(classCollection)
	if classCollection<>"" then
		classArray = Split(classCollection,",")
		for j=LBound(classArray) to UBound(classArray)
 			sql = "select * from stu_classlist where classid="&trim(classArray(j))
			set rs_classCollection = ado_query(sql)
			if not rs_classCollection.eof then
				showClassNameByClassCollection = showClassNameByClassCollection&"<div class='operList'><a class='demo' href='adminClassSex.asp?classid="&trim(classArray(j))&"'>["&rs_classCollection("className")&"]</a></div>"
			else 
				showClassNameByClassCollection = showClassNameByClassCollection&"<div class='operList'><a class='demo' href='adminClassSex.asp?classid="&trim(classArray(j))&"'>[未知班级]</a></div>"
			end if
			rs_classCollection.close : set rs_classCollection=nothing
		next
	end if
end function


'==================================================================================
'函数功能:返回当前学年划拨经费
'函数返回值:当前学年划拨经费cashValue
'参数说明:collegeid 学院ID
'Author:fty
'==================================================================================
function thisYearPlusCash(id)
	if id<>"" or not isNull(id) then
		sql="select cashValue from cw_cash where cashOperType=1 and isnotBigCash=1 and cashDate like '"&year(now())&"%' and collegeId="&id
		set rs_ThisYearPlusCash = ado_query(sql)
		if not rs_ThisYearPlusCash.bof then
			thisYearPlusCash = rs_ThisYearPlusCash("cashValue")
		else
			thisYearPlusCash = "未划拨"
		end if
		rs_ThisYearPlusCash.close : set rs_ThisYearPlusCash=nothing
	end if
end function


'==================================================================================
'函数功能:返回上学年余额
'函数返回值:上学年余额
'参数说明:collegeid 学院ID
'Author:fty
'==================================================================================
function lastYearRemainCash(id)
	 if id<>"" or not isNull(id) then
		 sql1="select SUM(cashValue) as cashValue1 from cw_cash where cashDate<'"&CStr(year(now()))&"-00-00' and cashOperType=1 and collegeId="&id
		 sql2="select SUM(cashValue) as cashValue2 from cw_cash where cashDate<'"&CStr(year(now()))&"-00-00' and cashOperType=2 and collegeId="&id
		 sql3="select remainValue from cw_remain where collegeId="&id
		 set rs1=ado_query(sql1)
		 set rs2=ado_query(sql2)
		 set rs3=ado_query(sql3)
		 if not isNull(rs1("cashValue1")) and not isNull(rs2("cashValue2")) and not isNull(rs3("remainValue")) then
		 	lastYearRemainCash = CDbl(rs1("cashValue1"))-CDbl(rs2("cashValue2"))+CDbl(rs3("remainValue"))
		 else
		 	lastYearRemainCash = "无内容"
		 end if
		 rs1.close : set rs1=nothing
		 rs2.close : set rs2=nothing
		 rs3.close : set rs3=nothing
	 end if
end function
%>